﻿
@{
    ViewBag.Title = "UserListIndex";
    Layout = "~/Views/Shared/_Layout.cshtml";

    List<MvcEntity.DemoUser> user = ViewBag.demoUsers as List<MvcEntity.DemoUser>;
}
<style>
    .rowtop {
        margin-top: 15px;
    }
</style>
<h2>UserListIndex</h2>
<div class="row">
    <form action="/User/UserListIndex" method="get">
        <div class="col-xs-4">
            <input type="text" name="UserName" class="form-control" placeholder="用户名">
        </div>
        <div class="col-xs-4">
            <input type="text" name="UserPhone" class="form-control" placeholder="手机号">
        </div>
        <div class="col-xs-4">
            <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search" aria-hidden="true"></span> 查询</button>
            <button type="reset" class="btn btn-default"><span class="glyphicon glyphicon-erase" aria-hidden="true"></span> 重置</button>
        </div>
    </form>
</div>
<div class="row rowtop">
    <div class="col-xs-12">
        <table class="table table-striped">
            <thead>
                <tr>
                    <td>用户名</td>
                    <td>手机号</td>
                    <td>最后登录时间</td>
                    <td>登录次数</td>
                    <td>创建时间</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                @{
                    if (user != null && user.Count > 0)
                    {
                        foreach (var item in user)
                        {
                            <tr>
                                <td>@item.UserName</td>
                                <td>@item.UserPhone</td>
                                <td>@item.LastDate.ToString("yyyy-MM-dd HH:mm:ss")</td>
                                <td>@item.LoginAt</td>
                                <td>@item.CreateDate.ToString("yyyy-MM-dd HH:mm:ss")</td>
                                <td>
                                    <a href="javascript:void(0)" onclick="deleteRow('@item.Id')">删除</a>
                                </td>
                            </tr>
                        }
                    }
                }


            </tbody>

        </table>
    </div>
</div>



@section scripts{
    <script type="text/javascript">
        function deleteRow(rowid) {
            if (confirm("确定要删除该用户吗？")) {
                request({
                    url: '/User/deleteRow',
                    data: { id: rowid },
                    success: function (data) {
                        if (data && data.code == 200) {
                            window.location.reload();
                        }
                        else {
                            alert(data.msg);
                        }
                    }
                })
            }
        }
    </script>
}